<?php
	session_start();

	removeAlbum();

	function removeAlbum(){
		$userName = $_SESSION['userName'];
		$album = $_GET['album'];
		
		$albumDir = '../users/'.$userName.'/'.$album;

		$response = array(
			'success' => false,
			'album' => $album,
			'user' => $userName
		);

		if(rrmdir($albumDir)){
			$response['success'] = true;
		}

		echo json_encode($response);
	}

	function rrmdir($dir) {
		if (is_dir($dir)) {
			$objects = scandir($dir);
			foreach ($objects as $object) {
				if ($object != "." && $object != "..") {
					if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
				}
			}
			reset($objects);
			return rmdir($dir);
		}
	}
?>